package com.example.hello.mapper;

import com.example.hello.pojo.PaymentLog;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PaymentLogMapper {

    @Insert("INSERT INTO user_payment_log(" +
            " user_id, biz_type, amount, balance_before, balance_after, remark" +
            ") VALUES(" +
            " #{userId}, #{bizType}, #{amount}, #{balanceBefore}, #{balanceAfter}, #{remark}" +
            ")")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(PaymentLog log);

    @Select("SELECT id, user_id AS userId, biz_type AS bizType, amount, " +
            "balance_before AS balanceBefore, balance_after AS balanceAfter, " +
            "remark, created_at AS createdAt " +
            "FROM user_payment_log " +
            "WHERE user_id = #{userId} " +
            "ORDER BY created_at DESC")
    List<PaymentLog> selectByUserId(@Param("userId") Long userId);
}